package com.gjj.echarts.echartsgjj.controller;

import com.gjj.echarts.echartsgjj.service.OneMonthService;
import com.gjj.echarts.echartsgjj.service.OneYearService;
import com.gjj.echarts.echartsgjj.vo.OneMonthVo;
import com.gjj.echarts.echartsgjj.vo.OneYearVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class ChartController {
    @Autowired
    OneYearService oneYearService;
    @Autowired
    OneMonthService oneMonthService;

    @GetMapping("/month_money_chart")
    public String monthMoneyChart(@RequestParam(value = "method",defaultValue = "money")String method, Model model){
        OneYearVo oneYearVo = oneYearService.selectOneYear();
        model.addAttribute("year",oneYearVo);
        model.addAttribute("method",method);
        return "charts/month_money_chart";
    }

    @GetMapping("/everymonth_chart")
    public String everyMonthMoneyChart(@RequestParam(value = "month",defaultValue = "1") Integer month,
                                       @RequestParam(value = "method",defaultValue = "money")String method,
                                       Model model){
        OneMonthVo oneMonthVo = null;
        if (month<=12){
            oneMonthVo = oneMonthService.selectOneMonth(month);
        }else {
            oneMonthVo = oneMonthService.selectTwelveMonth();
        }
        model.addAttribute("month",oneMonthVo);
        model.addAttribute("method",method);
        return "charts/everymonth_chart";
    }
}
